<template>
  <div class="goods-tabs">
    <!-- 切换菜单 -->
    <nav>
      <a
        @click="changeTab('GoodDetail')"
        :class="{ active: activeMenu === 'GoodDetail' }"
        href="javascript:;"
        >商品详情</a
      >
      <a
        @click="changeTab('GoodComment')"
        :class="{ active: activeMenu === 'GoodComment' }"
        href="javascript:;"
        >商品评价<span>600+</span></a
      >
    </nav>
    <!-- 这个位置显示对应的组件 GoodsDetail 或者 GoodsComment -->
    <!-- 动态组件：动态切换不同的组件
    用法：必须是动态绑定:is="变量" (变量值是切换组件的标签名)
     -->
    <keep-alive include="GoodsDetail">
      <component :is="activeMenu" />
    </keep-alive>
  </div>
</template>
<script>
import { ref } from 'vue'
import GoodDetail from './goods-detail.vue'
import GoodComment from './goods-comment.vue'
export default {
  name: 'GoodsTabs',
  components: {
    GoodDetail,
    GoodComment
  },
  setup () {
    // 商品详情=> GoodDetail | 商品评价=> GoodComment => 当前选中的组件的标签名
    const activeMenu = ref('GoodComment')
    // 切换tab
    const changeTab = (tab) => {
      activeMenu.value = tab
    }
    return { activeMenu, changeTab }
  }
}
</script>
<style scoped lang="less">
.goods-tabs {
  min-height: 600px;
  background: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      > span {
        color: @priceColor;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child {
        border-right: 1px solid #f5f5f5;
      }
      &.active {
        &::before {
          content: "";
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: @xtxColor;
        }
      }
    }
  }
}
</style>
